package com.example.mobile0123456789hwh0509;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import androidx.appcompat.app.AppCompatActivity;

public class LoginActivity extends AppCompatActivity {

    private EditText edtTxtLoginUserName;
    private EditText edtTxtLoginPassword;
    private Button btnLogin;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        initView();
        btnLogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent=new Intent(LoginActivity.this,ShowDataActivity.class);
                String userName=edtTxtLoginUserName.getText().toString().trim();
                String password=edtTxtLoginPassword.getText().toString().trim();
//              第一种方式 putExtra
                intent.putExtra("name",userName);
//                第二种方式 Bundle
                Bundle bundle=new Bundle();
                bundle.putString("psw",password);
                intent.putExtras(bundle);

                startActivity(intent);
            }
        });
    }

    private void initView() {
        edtTxtLoginUserName = (EditText) findViewById(R.id.edtTxtLoginUserName);
        edtTxtLoginPassword = (EditText) findViewById(R.id.edtTxtLoginPassword);
        btnLogin = (Button) findViewById(R.id.btnLogin);
    }
}